package com.example.demo.service;

import org.springframework.stereotype.Service;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

@Service
public class ImageService {

    public byte[] getImageAsBytes(String imageName) throws IOException {
        // 图片存储的路径
        String imagePath = "/www/wwwroot/peanutPhotos";
        File file = new File(imagePath + File.separator + imageName);
        if (file.exists()) {
            try (InputStream inputStream = new FileInputStream(file)) {
                return inputStream.readAllBytes();
            }
        } else {
            throw new IOException("File not found: " + imageName);
        }
    }
}
